package model

import (
	"gpt-api/framework/db"
)

type EventImage struct {
	db.BaseModel
	EventID  uint   `json:"event_id" gorm:"column:event_id;type:int;not null;comment:事件ID"`
	ImageUrl string `json:"image_url" gorm:"column:image_url;type:varchar(255);default:'';comment:图片地址"`
	UserID   uint   `json:"user_id" gorm:"column:user_id;type:int;default:0;comment:用户ID"`
	MemberID uint   `json:"member_id" gorm:"column:member_id;type:int;default:0;comment:所属成员ID"`
}

func (EventImage) TableName() string {
	return "event_images"
}

// 根据用户ID,成员ID统计图片数量
func (e EventImage) CountEventImageByUserIdAndMemberId(database *db.DB, userId uint64, memberId uint64) int64 {
	var count int64
	database.Model(&EventImage{}).Where("user_id = ? and member_id = ?", userId, memberId).Count(&count)
	return count
}

// 根据用户ID,成员ID查询图片列表
func (e EventImage) GetEventImagesByEventId(database *db.DB, userId uint64, memberId uint64) ([]EventImage, error) {
	var eventImages []EventImage
	err := database.Model(&EventImage{}).Where("user_id = ? and member_id = ?", userId, memberId).Find(&eventImages).Error
	return eventImages, err
}
